package util
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	/**
	 * Singleton Helper for non UI-Classes to dispatch events. 
	 * Delegates all work to an EventDispatcher. 
	 * 
	 * @author jbaeck
	 * 
	 */
	public class EvtDispatchHelper implements IEventDispatcher
	{
		private static var m_instance:EvtDispatchHelper = new EvtDispatchHelper();
		protected var m_dispatcher:EventDispatcher;
		
		public function EvtDispatchHelper()
		{
			if(m_instance != null)
			{
				throw Error("This class is a singleton - user getInstance - no more then 1 instance per vm!!!!!");
			}
			m_dispatcher = new EventDispatcher(this);
		}
		
		public static function getInstance():EvtDispatchHelper
		{
			return m_instance;
		}

		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			m_dispatcher.addEventListener(type,listener,useCapture,priority,useWeakReference);
		}
		
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			m_dispatcher.removeEventListener(type,listener,useCapture);
		}
		
		public function dispatchEvent(event:Event):Boolean
		{
			return m_dispatcher.dispatchEvent(event);
		}
		
		public function hasEventListener(type:String):Boolean
		{
			return m_dispatcher.hasEventListener(type);
		}
		
		public function willTrigger(type:String):Boolean
		{
			return m_dispatcher.willTrigger(type);
		}
		
	}
}